package com.xhui.vimarket.zkplus.zul.attr.rule;

import java.util.ArrayList;

import org.zkoss.zk.ui.Component;

import com.xhui.crm.common.Constants;
import com.xhui.crm.common.util.numeric.NumericUtil;
import com.xhui.crm.common.util.string.StrUtil;
import com.xhui.crm.common.vo.RetVO;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attr.bean.com.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusil;
import com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp;

/**
 * AttrValueLengthRule.
 * 
 * @版权：福富软件 版权所有 (c) 2011
 * @author wuyx
 * @version Revision 1.0.0
 * @see:
 * @创建日期：2011-3-23
 * @功能说明：
 * 
 */
public final class AttrValueLengthRule {
    
    /**
     * 构造函数.
     * 
     * @author wuyx
     * 2011-3-23 wuyx 
     */
    private AttrValueLengthRule() {
    }
    
    /**
     * judge.
     * 
     * @param valList ArrayList<AttrInst>
     * @param rootComp Component
     * @return RetVO
     * @author wuyx
     * 2011-3-23 wuyx 
     */
    public static RetVO judge(ArrayList<AttrInst> valList, Component rootComp) {
        RetVO retVo = RetVO.newInstance(Constants.RET_TRUE, "");
        if (valList != null && valList.size() > 0) { // 默认的判断方式
            String sSetLength = AttrCompUtil.getCompAttrStr(rootComp,
                AttrBaseComp.COMP_VALUE_LENGTH);
            if (sSetLength != null) { // 有配置，需判断
                int setLength = NumericUtil.toInt(sSetLength);
                if (setLength > 0) { // 需要判断
                    AttrInst inst = valList.get(0);
                    if (StrUtil.getLength(inst.getParam1()) > setLength) {
                        retVo.setResult(Constants.RET_FALSE);
                        retVo.setRetMsg(AttrCompUtil.getCompName(rootComp) + "值长度："
                            + StrUtil.getLength(inst.getParam1()) + "，不符合限制值：" + setLength);
                    }
                }
            }
        }
        return retVo;
    }
    
    /**
     * judge.
     * 
     * @param valList ArrayList<AttrInst>
     * @param rootComp Component
     * @return RetVO
     * @author wuyx
     * 2011-3-23 wuyx 
     */
    public static RetVO judgePassword(ArrayList<AttrInst> valList, Component rootComp) {
        return judge(valList, rootComp);
    }
}
